# Copyright (c) 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# GNU Makefile based on shared rules provided by the Native Client SDK.
# See README.Makefiles for more details.


EXTRA_INCS := -isystem $(SRC_ROOT)/../libc -isystem $(SRC_ROOT)../safe-iop/include
EXTRA_INCS += -Iarch/nacl -Wall -Werror
CFLAGS += -DFLOATING_POINT -DINET6 -DUSG_COMPAT -gdwarf-3
CFLAGS += -DANDROID_SMP=1 -D_GNU_SOURCE -DHAVE_MORECORE=0 -DLINKER_DEBUG=1
CFLAGS += -DALLOW_SYMBOLS_FROM_MAIN

X86_32_CFLAGS += -DANDROID_X86_LINKER -DUSES_SSE2 
X86_64_CFLAGS += -DANDROID_X86_64_LINKER
ARM_CFLAGS += -DANDROID_ARM_LINKER

ifeq ($(NACL_ARCH),arm)
ARCH_FLAGS:=$(ARM_CFLAGS)
else
ARCH_FLAGS:=$(X86_CFLAGS)
endif


RUNNABLE_SOURCES = \
  debug_map.c \
  dlfcn.c \
  linker.c \
  linker_environ.c \
  linker_format.c \
  linker_phdr.c \
  rt.c \
  arch/nacl/begin.c \
  arch/nacl/nacl_dyncode_alloc.c \
  arch/nacl/nacl_dyncode_map.c


RUNNABLE_LD:=-nostdlib -static -lc -Wl,-Ttext,0x20000
RUNNABLE_OBJECTS := $(subst .c,.o,$(subst .cpp,.o,$(RUNNABLE_SOURCES)))
$(foreach src,$(RUNNABLE_SOURCES),$(eval $(call BASIC_COMPILE_TARGET,$(basename $(src)).o,$(SRC_ROOT)/$(src),$(CC),-std=gnu99 -g -O0 $(CFLAGS) $(EXTRA_INCS) $(ARCH_FLAGS))))
$(eval $(call BASIC_LINK_TARGET,$(INS_ROOT)/runnable-ld.so,$(RUNNABLE_OBJECTS),$(CC),$(RUNNABLE_LD),,-lsupc++ -lc -lgcc_eh -lgcc -g,$(INS_ROOT)/libc.a))
